﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Pow {
	class EnemyFactory : List<Enemy> {
		Game1 game;
		public int totalEnemies = 5;
		//List<Enemy> enemyPool;

		public EnemyFactory(Game game, Jogador jogador) {
			this.game = game as Game1;
			//enemyPool = new List<Enemy>(15);

			for (int i = 0; i < totalEnemies; i++)
				Add(_createEnemy(jogador));

			Console.WriteLine(this.Count);
		}

		public void Spawn() {
			foreach (Enemy e in this)
				if (e.active == false) {
					e.Spawn();
					return;
				}
		}

		private Enemy _createEnemy(Jogador jogador) {
			Enemy me = new Enemy(game, jogador);
			//me.active=false;
			return me;
		}


		int oldSecond = 0;

		public void Update(GameTime gameTime) {
			if (oldSecond == 0) oldSecond = gameTime.TotalGameTime.Seconds;
			if (gameTime.TotalGameTime.Seconds != oldSecond) {
				Spawn();
				oldSecond = gameTime.TotalGameTime.Seconds;
			}

			foreach (Enemy e in this)
				e.Update(gameTime);
		}

		public void Draw(GameTime gameTime) {
			foreach (Enemy e in this)
				e.Draw(gameTime);
			//game.spriteBatch.Draw(texture, myPosition, Color.White);
		}


	}
}
